﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Globalization;

namespace OOLib
{
   /// <summary>
   /// Specifies the basic operations for a window component. 
   /// </summary>
   /// <remarks>
   /// A window is a rectangular region on an output device with its own position, size, and internal coordinate system. 
   /// A window is used for displaying data. In addition, the window receives events from the user.
   /// </remarks>
   public class Window : Component, IWindow
   {
      #region Constructors

      /// <summary>
      /// Constructor
      /// </summary>
      /// <remarks>
      /// After using this constructor, the ComObj must be set manually!
      /// </remarks>
      public Window() :
         base()
      { }

      /// <summary>
      /// Constructor
      /// </summary>
      /// <param name="comObject">COM object</param>
      public Window(object comObject) :
         base(comObject)
      { }

      #endregion

      /*
      #region Listener
      
      private WindowListener _WindowListener = null;

      /// <summary>
      /// Is called when the ComObj is finally set.
      /// </summary>
      protected override void OnComObjSet()
      {
         base.OnComObjSet();

         _WindowListener = new WindowListener();
         InvokeMethod("addWindowListener", _WindowListener);
      }

      /// <summary>
      /// Disposes the object.
      /// </summary>
      /// <remarks>
      /// This is the .Net Dispose() and will onyl dispose the wrapper.
      /// Call OODispose() to dispose the OpenOffice object.
      /// </remarks>
      protected override void Dispose(bool disposing)
      {
         if (ComObj != null)
         {
            try
            {
               InvokeMethod("removeWindowListener", _WindowListener);
            }
            catch { }
         }
         _WindowListener = null;

         base.Dispose(disposing);
      }

      #endregion
      */

      #region IWindow

      /// <summary>
      /// Sets the outer bounds of the window. 
      /// </summary>
      /// <param name="x">The x-coordinate of the window.</param>
      /// <param name="y">The y-coordinate of the window. </param>
      /// <param name="width">The width of the window. </param>
      /// <param name="height">The height of the window. </param>
      /// <param name="flags">Flags are of type PosSize and specify, which parameters are taken 
      /// into account when setting the outer bounds of the window. </param>
      /// <remarks>!!! Not tested !!!</remarks>
      public void SetPosSize(int x, int y, int width, int height, short flags)
      {
         CheckDisposed();
         InvokeMethod("setPosSize", x, y, width, height, flags);
      }

      /// <summary>
      /// Returns the outer bounds of the window. 
      /// </summary>
      /// <returns>Returns the outer bounds of the window.</returns>
      /// <remarks>!!! Not tested !!!</remarks>
      public Rectangle GetPosSize()
      {
         CheckDisposed();
         return GetObjectWrapper<Rectangle>(InvokeMethod("getPosSize"));
      }

      /// <summary>
      /// Shows or hides the window depending on the parameter. 
      /// </summary>
      /// <param name="visible">true for visible, otherwise false</param>
      public void SetVisible(bool visible)
      {
         CheckDisposed();
         InvokeMethod("setVisible", visible);
         _IsVisible = visible;
         NotifyPropertyChanged("IsVisible");
      }

      private bool _IsVisible = true;

      /// <summary>
      /// Gets or sets if the window is visible.
      /// </summary>
      /// <remarks>
      /// The read support for the IsVisible property is maintained in C# code.
      /// So it may be out of sync eventually.
      /// </remarks>
      public bool IsVisible
      {
         get
         {
            CheckDisposed();
            return _IsVisible;
         }
         set
         {
            SetVisible(value);
         }
      }

      /// <summary>
      /// Enables or disables the window depending on the parameter.
      /// </summary>
      /// <param name="enable">true to enable, otherwise false</param>
      /// <remarks>!!! Not tested !!!</remarks>
      public void SetEnable(bool enable)
      {
         CheckDisposed();
         InvokeMethod("setEnable", enable);
         _IsEnabled = enable;
         NotifyPropertyChanged("IsEnabled");
      }

      private bool _IsEnabled = true;

      /// <summary>
      /// Gets or sets if the window is enabled.
      /// </summary>
      /// <remarks>
      /// The read support for the IsEnabled property is maintained in C# code.
      /// So it may be out of sync eventually.
      /// </remarks>
      public bool IsEnabled
      {
         get
         {
            CheckDisposed();
            return _IsEnabled;
         }
         set
         {
            SetEnable(value);
         }
      }

      /// <summary>
      /// Sets the focus to the window. 
      /// </summary>
      /// <remarks>!!! Not tested !!!</remarks>
      public void SetFocus()
      {
         CheckDisposed();
         InvokeMethod("setFocus");
      }

      #endregion
   }

   /// <summary>
   /// Specifies the basic operations for a window component. 
   /// </summary>
   /// <remarks>
   /// A window is a rectangular region on an output device with its own position, size, and internal coordinate system. 
   /// A window is used for displaying data. In addition, the window receives events from the user.
   /// </remarks>
   public interface IWindow
   {
      /// <summary>
      /// Sets the outer bounds of the window. 
      /// </summary>
      /// <param name="x">The x-coordinate of the window.</param>
      /// <param name="y">The y-coordinate of the window. </param>
      /// <param name="width">The width of the window. </param>
      /// <param name="height">The height of the window. </param>
      /// <param name="flags">Flags are of type PosSize and specify, which parameters are taken 
      /// into account when setting the outer bounds of the window. </param>
      void SetPosSize(int x, int y, int width, int height, short flags);

      /// <summary>
      /// Returns the outer bounds of the window. 
      /// </summary>
      /// <returns>Returns the outer bounds of the window.</returns>
      Rectangle GetPosSize();

      /// <summary>
      /// Shows or hides the window depending on the parameter. 
      /// </summary>
      /// <param name="visible">true for visible, otherwise false</param>
      void SetVisible(bool visible);

      /// <summary>
      /// Gets or sets if the window is visible.
      /// </summary>
      bool IsVisible { get; set; }

      /// <summary>
      /// Enables or disables the window depending on the parameter.
      /// </summary>
      /// <param name="enable">true to enable, otherwise false</param>
      void SetEnable(bool enable);

      /// <summary>
      /// Gets or sets if the window is enabled.
      /// </summary>
      bool IsEnabled { get; set; }

      /// <summary>
      /// Sets the focus to the window. 
      /// </summary>
      void SetFocus();
   }

   //todo check why Listeners are not working
   /*   
   /// <summary>
   /// Implementation of Window listener
   /// </summary>
   [ComVisible(true)]
   [ClassInterface(ClassInterfaceType.AutoDispatch)]
   public class WindowListener : IEventListener, IWindowListener, IWindowListener2
   {

      public void disposing(object source)
      {
      }

      public void windowResized(object e)
      {
      }

      public void windowMoved(object e)
      {
      }

      public void windowShown(object e)
      {

      }

      public void windowHidden(object e)
      {

      }

      public void windowEnabled(object e)
      {

      }

      public void windowDisabled(object e)
      {

      }
   }

   [ComVisible(true)]
   [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
   public interface IEventListener
   {
      void disposing(object source);
   }

   [ComVisible(true)]
   [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
   public interface IWindowListener : IEventListener
   {
      void windowResized(object e);

      void windowMoved(object e);

      void windowShown(object e);

      void windowHidden(object e);
   }

   [ComVisible(true)]
   [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]
   public interface IWindowListener2 : IWindowListener
   {
      void windowEnabled(object e);

      void windowDisabled(object e);
   }
   */
}
